<?php
	class TinyMVC_Library_Template{
		private $tmvc = null;
		private $theme = 'theme_view';
		private $assigned = 0;
		private $errors = Array();
	
		function __construct(){
			if(!$this->tmvc){
				$this->tmvc = tmvc::instance();
			}
		}
	
		function display($data, $left_menu){
			if (isset($data) && isset($left_menu) && isset($this->tmvc)){
				try{
					$this->tmvc->controller->view->assign('left_menu', $left_menu);
					$this->tmvc->controller->view->assign('site_body', $data);
					$this->tmvc->controller->view->display($this->theme);
				} catch(Exception $e){
					$this->error($e->getMessage());
				}
			}
		}
	
		public function fetch($view){
			if (isset($this->tmvc, $view)){
				try{
					$this->tmvc->controller->view->fetch($view);
				}catch(Exception $e){
					$this->error($e->getMessage());
				}
			}
		}
	
		public function assign($var, $val){
			if(isset($var, $val, $this->tmvc)){
				try{
					$this->tmvc->controller->view->assign($var, $val);
					$this->assigned++;
				}catch(Exception $e){
					$this->error($e->getMessage());
				}
			}
		}
	
		private function error($msg){
			if(isset($msg)){
				$this->errors[] = $msg;
			}
		}
	
		public function getErrors(){
			return $this->errors;
		}
	}
?>